function relod() {
    layui.use('table', function() {
        var table = layui.table;
        table.reload('test', {
            page: {
                curr: 1 //重新从第一页开始
            }, where: {
                spplierName: $("#spplierName").val()
            }
        })
    })
}
layui.use(['table','layer'], function(){
    var table = layui.table;
    table.render({
        elem: '#test'
        ,url:'htz/supplier/sel'
        ,toolbar: '#toolbarDemo',
        parseData: function(res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.obj.total, //解析数据长度
                "data": res.obj.list//解析数据列表
            };
        }
        ,cols: [[
            {type:'radio',width:40}
            ,{field:'supplierId', width:80, title: 'ID', sort: true}
            ,{field:'supplierName', width:100, title: '提供商名字'}
            ,{field:'address', width:250, title: '地址', sort: true}
            ,{field:'phone', width:150, title: '联系号码'}
            // ,{field:'sign', title: '签名', minWidth: 100}
            // ,{field:'experience', width:80, title: '积分', sort: true}
            // ,{field:'score', width:80, title: '评分', sort: true}
            // ,{field:'classify', width:80, title: '职业'}
            // ,{field:'wealth', width:135, title: '财富', sort: true}
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:120}
        ]]
        ,page: true
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
        switch(obj.event){
            case 'getCheckData':
                var data = checkStatus.data;  //获取选中行数据
                if (data!=""){
                    layer.open({
                        type:2,
                        area:["600px","400px"],
                        content:"role_jurisdiction.html"
                    })
                }else {
                    layer.alert("请选择一个角色")
                }
                // layer.alert(JSON.stringify(data));
                break;
        };
    });

    table.on('tool(test)', function(obj){
        var data = obj.data; //获取选中行状态
        if (obj.event === 'edit'){
            layui.use('layer',function () {
                var layer = layui.layer;
                layer.open({
                    type: 2,
                    area: ['600px','350px'],
                    content: 'provider_upd.html',
                    success: function (layero,index) {
                        var iframe = window['layui-layer-iframe'+index]
                        iframe.loa(data);
                    }
                })
            })
        }else if (obj.event === 'del') {
            var layer = layui.layer;
            layer.confirm('真的删除行么', function(index){
                $.post("htz/supplier/del",{supplierId:data.supplierId},function (res) {
                    if (res.obj>0){
                        layer.msg("删除成功")
                        relod();
                    }else {
                        layer.msg("删除失败，请重试")
                    }
                })
            },function (index) {
                layer.msg("已取消删除")
            });
        }
    });
    layui.$("#ad").on('click',function () {
        layui.use('layer',function () {
            var layer = layui.layer;
            layer.open({
                type: 2,
                area: ['800px','350px'],
                content: 'provider_add.html'
            })
        })
    })
});